import 'package:json_annotation/json_annotation.dart';

part 'merchant.g.dart';

@JsonSerializable()
class MallMerchant {
  final int id; // 商户ID
  final String name; // 商户名称
  final String desc; // 描述
  final String logo; // logo
  final String contactEmail; // 联系邮箱
  final String contactPhone; // 联系电话
  final int status; // 状态: 1=正常, 0=禁用

  MallMerchant({
    required this.id,
    required this.name,
    required this.desc,
    required this.logo,
    required this.contactEmail,
    required this.contactPhone,
    required this.status,
  });

  /// 从 JSON 反序列化
  factory MallMerchant.fromJson(Map<String, dynamic> json) {
    return MallMerchant(
      id: json['id'] is String ? int.parse(json['id']) : json['id'] ?? 0,
      name: json['name'] ?? '',
      desc: json['desc'] ?? '',
      logo: json['logo'] ?? '',
      contactEmail: json['contactEmail'] ?? '',
      contactPhone: json['contactPhone'] ?? '',
      status: json['status'] ?? 0,
    );
  }

  /// 转 JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'desc': desc,
      'logo': logo,
      'contactEmail': contactEmail,
      'contactPhone': contactPhone,
      'status': status,
    };
  }
}
